﻿using System;
using System.Xml;
using System.Text;
using InfoJetSoft.Service.Entity;
using InfoJetSoft.Service.Util;

namespace InfoJetSoft.Service.Worker
{
	
	class XSNTemplateParseWorker
	{
		
		public static void  parseTemplate(Manifest manifest)
		{
			XmlElement root = manifest.Doc.DocumentElement;
			string xsfPrefix = manifest.XsfPrefix;
			StringBuilder initXMLFilterBuffer = new StringBuilder();
			initXMLFilterBuffer.Append("//");
			initXMLFilterBuffer.Append(NamespaceUtil.toFullName(xsfPrefix, "fileNew"));
			initXMLFilterBuffer.Append("/");
			initXMLFilterBuffer.Append(NamespaceUtil.toFullName(xsfPrefix, "initialXmlDocument"));
			XmlElement initXmlElement = (XmlElement) DOMUtil.selectOneNode(root, initXMLFilterBuffer.ToString(), manifest.NsResolver);
			string templateName = initXmlElement.GetAttribute("href");
			CABFile cabFile = CABFileFinder.findCABFile(manifest, templateName);
			XmlDocument doc = DOMUtil.buildDoc(cabFile.ByteOutput);
			Template template = new Template();
			template.Doc = doc;
			template.NsResolver = new NamespaceResolver(doc);
			template.CabFile = cabFile;
			template.XmlName = templateName;
			manifest.Template = template;
		}
	}
}